#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: GRDemo
# Author: Chris Evans, Garrett Vanhoy
# Generated: Mon Aug  1 13:55:29 2011
##################################################


from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.gr import firdes
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import wx
import time
import BPSK, QPSK, QAM16, TCPSink
import threading
class GRDemo():

	def __init__(self):
		self.mod = 1
		self.txamp = 1
		self.noise = 0
		self.top_block = BPSK.BPSK(self.txamp, self.noise)
		print "started"

		
	def set_mod(self, mod):
		self.mod = mod
		self.mutate(self.mod)
		
	def set_txamp(self, amp):
		self.txamp = amp
		self.mutate(self.mod)
		
	def set_noise(self, noise):
		self.noise = noise
		self.mutate(self.mod)
		
	def get_noise(self):
		return self.noise
		
	def mutate(self, mod):
		self.top_block.stop()
		if mod == 1:
			self.top_block = BPSK(self.txamp, self.noise)
		elif mod == 2:
			self.top_block = QPSK(self.txamp, self.noise)
		elif mod == 3:
			self.top_block = PSK8(self.txamp, self.noise)
		else:
			self.top_block = QAM16(self.txamp, self.noise)
		self.top_block.start()
		self.top_block.wait()
		
	def get_BER(self):
		self.top_block.start()
		time.sleep(1)
		self.top_block.stop()
		length = 0
		print "Get BER"
		while length is 0:
			length = len(self.top_block.gr_vector_sink_x_0.data())
		return self.top_block.gr_vector_sink_x_0.data()[length - 1]

if __name__ == '__main__':
	tb = GRDemo()
	tb.get_BER()

